package com.woniuxy.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.woniuxy.entity.Department;
import com.woniuxy.entity.Store_House;
import com.woniuxy.mapper.Store_HouseMapper;
import com.woniuxy.service.Store_HouseService;
import com.woniuxy.utils.KeyUtil;
@Service
public class Store_HouseServiceImpl implements Store_HouseService{
	@Autowired
	private Store_HouseMapper store_HouseMapper;

	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	@Override
	public List<Store_House> findStore_House() {
		String key=KeyUtil.generate(this, "findStore_House");
		if (redisTemplate.hasKey(key)) {
			List<Object> objects=redisTemplate.opsForList().range(key, 0, redisTemplate.opsForList().size(key));
			List<Store_House> store_Houses=new ArrayList<Store_House>();
			ArrayList<Object> data=(ArrayList<Object>) objects.get(0);
			for (Object object : data) {
				store_Houses.add((Store_House)object);
			}
			return store_Houses;
		}else{
			List<Store_House> store_Houses=store_HouseMapper.findStore_House();
			redisTemplate.opsForList().leftPushAll(key, store_Houses);
			redisTemplate.expire(key, 1, TimeUnit.DAYS);
			return store_Houses;
		}
	}
}
